package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        Scanner scanner=new Scanner(System.in);

        System.out.print("请输入需要删除的书名：");
        String name=scanner.nextLine();

        int currentSize=bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            if(name.equals(bookList.getBooks(i).getName())) {
                //简单一点，这里使用覆盖删除！
                for (int j = i; j < currentSize-1; j++) {
                    Book book=bookList.getBooks(j+1);
                    bookList.setBook(j,book);
                }
                bookList.setBook(currentSize,null);
                bookList.setUsedSize(currentSize-1);
                System.out.println("删除成功！");
                return;
            }
        }
        System.out.println("未找到此书！");
    }
}
